package zsw.rocketmqs.Demo;

import org.apache.rocketmq.common.message.MessageExt;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

import web.dao.AccountMapper;
import zsw.model.Account;
import zsw.rocketmqs.RocketmqEvent;

@Component
public class ConsumerDemo {
	
	
	@Autowired
	private AccountMapper accountMapper;
	
	
	@EventListener(condition = "#event.msgs[0].topic=='TopicTest1' && #event.msgs[0].tags=='TagA'")
	public void rocketmqMsgListen(RocketmqEvent event) throws Exception {
//      DefaultMQPushConsumer consumer = event.getConsumer();
		try {
			MessageExt messageExt = event.getMsgs().get(0);
			int queueId = messageExt.getQueueId();
			// int i=1/0;
			System.out.println(event.getCustomeName() + "::com.guosen.client.controller.consumerDemo1监听到一个消息达到：Body"
					+ new String(messageExt.getBody(), "utf-8") + "::****消息的quenID:" + queueId);
//           System.out.println("com.guosen.client.controller.consumerDemo监听到一个消息达到：meaasgeId" + event.getMsgs().get(0).getMsgId());
		/*	System.out.println(event.getCustomeName() + "::com.guosen.client.controller.consumerDemo1监听到一个消息达到：keys"
					+ messageExt.getKeys());*/
			
			/*Account a=new Account();
			a.setMoneyNum(Integer.valueOf(new String(messageExt.getBody(), "utf-8")));
			a.setUserName("B");
			accountMapper.updateAcountPlus(a);*/
			
			// TODO 进行业务处理
		} catch (Exception e) {
			e.printStackTrace();
			throw e;
		}
	}
}
